# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator

jdbcUrl='{{ var.json.oracle_tms_pro.url }}'
username='{{ var.json.oracle_tms_pro.username }}'
password='{{ var.json.oracle_tms_pro.password }}'
nowdt='{{ execution_date | cst_ds }}'
nextdt='{{ execution_date | date_add(1) | cst_ds }}'
table="tms_city_prescription_config"
env='{{ var.value.env_sync }}'

jsonpara="""{
"reader":{
"connect":{
"url":"jdbcUrlpara",
"username":"usernamepara",
"password":"passwordpara",
"driver":"oracle.jdbc.driver.OracleDriver"
},
"dbtype":"oracle",
"tableName":"tablepara",
"where":"1=1",
"query":"",
"splitColumn":"",
"equalitySectioning":1,
"containsnull":0,
"fetchsize":"1024",
"threadNumber":1
},
"channel":{
"filterAbnormalCharacter":1
},
"writer":{
"dbtype":"hive",
"tableName":"tablepara",
"database":"jms_ods",
"writeMode": "overwrite",
"partitionColumn":"dt",
"partitionValue":"nowdt"},
"settting":{
"env":"envpara"}
}""".replace("jdbcUrlpara",jdbcUrl).replace("usernamepara",username).replace("passwordpara",password). \
    replace("nowdt",nowdt).replace("nextdt",nextdt). \
    replace("tablepara",table). \
    replace("envpara",env)



jms_ods__tms_city_prescription_config = SparkSubmitOperator(
    task_id='jms_ods__tms_city_prescription_config',
    email=['rabie.zhuang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_ods__tms_city_prescription_config_{{ execution_date | date_add(1) | cst_ds }}',
    pool='oracle_tms',
    pool_slots=1,
    execution_timeout=timedelta(minutes=30),
    driver_memory='2G',
    executor_memory='2G',
    executor_cores=2,
    num_executors=1,
    java_class='com.yunlu.bigdata.jobs.synchrotool.DataSynchDriver',  # spark 主类
    application='hdfs:///scheduler/jms/spark/sync/spark_sync.jar',  # spark jar 包
    application_args=[jsonpara,],
    sla=timedelta(hours=2),
)



# from airflow.operators.dummy_operator import DummyOperator
#
# jms_ods__yl_tms_airport_line = DummyOperator(
#     task_id='jms_ods__yl_tms_airport_line',
#     retries=0,
#     priority_weight=0,
#     # sla=timedelta(hours=2),
# )